lappend auto_path "../"
package require GlobalPathName 1.0
package require ElementTypeScript 1.0
package require CBARScript 1.0

namespace eval GUI {
  namespace export NastranTreeGUI
}

# 创建一个目录树，并为其添加三个顶层条目，还会为每个顶层条目创建一些子条目。
# 语法：ttk::treeview pathname ?option?
proc GUI::NastranTreeGUI {} {
  global nastranTreeWindow
  ttk::treeview $nastranTreeWindow -columns 1
  grid $nastranTreeWindow -row 0 -column 0
  # 顶层显示文本
  $nastranTreeWindow column #0 -width 150
  $nastranTreeWindow heading #0 -text "Operation"
  $nastranTreeWindow column #1 -width 250
  $nastranTreeWindow heading #1 -text "Description"
  # 顶层条目一：Pretreatment
  # 语法：pathname insert parent index ?-id id? options...
  # 创建一个新项，parent是父项id，或用空字符串{}来创建一个新的顶级项。
  # index 是一个整数，若值为end表示指定在父的子列表中插入新项的位置。index ≤ 0，在开头插入；index ≥ 当前的子节点树，在末尾插入。
  # 如果指定了 -id，它将用作项目标识符，id必须不存在于树中。
  $nastranTreeWindow insert {} end -id pretreatment -text "Pretreatment"
  $nastranTreeWindow insert {} end -id loadstep -text "LoadStep"
  $nastranTreeWindow insert {} end -id boundary -text "Boundary"

  # 将子条目信息以列表形式存储
  # 父项id 子项目标识符 子项目文本 值（描述说明） 脚本文件

  set pretreatmentList {
    pretreatment p1 ElementType "change element type" Script::ElementTypeScript
    pretreatment p2 CBAR "CBAR simulation of axle pin" Script::CBARScript
  }
  set loadstepList {
    loadstep l1 LoadingStep "LoadingStep"
    loadstep l2 ControlCard "ControlCard"
  }
  set boundaryList {
    boundary b1 SPC "SPC"
    boundary b2 Force "Force"
  }
  foreach {parent id operation description script} $pretreatmentList {
    $nastranTreeWindow insert $parent end -id $id -text $operation -values [list $description] -tags $operation
    $nastranTreeWindow tag bind $operation <ButtonRelease> $script
  }

  foreach {parent id text value} $loadstepList {
    $nastranTreeWindow insert $parent end -id $id -text $text -values [list $value]
  }
  foreach {parent id text value} $boundaryList {
    $nastranTreeWindow insert $parent end -id $id -text $text -values [list $value]
  }
}
# NotebookNastranGUI

# 打包操作
package provide NotebookNastranGUI 1.0